home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / cli / WDelta.lha / WDelta / src / wpatch.asm < prev   
Encoding:
Assembly Source File  |  1999-07-07  |  7.5 KB  |  374 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    wpatch.asm
  3. ;  :Contents.    apply wdelta file
  4. ;  :Author.    Bert Jahn
  5. ;  :EMail.    wepl@kagi.com
  6. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  7. ;  :Version.    $Id: wpatch.asm 1.0 1999/07/06 21:58:56 jah Exp jah $
  8. ;  :History.    06.07.99 separated from wdelta
  9. ;  :Requires.    OS V37+
  10. ;  :Copyright.
  11. ;        WPatch is Copyright © 1999 Bert Jahn <wepl@kagi.com>
  12. ;
  13. ;        This program is free software; you can redistribute it and/or
  14. ;        modify it under the terms of the GNU General Public License as
  15. ;        published by the Free Software Foundation; either version 2 of
  16. ;        the License, or (at your option) any later version.
  17. ;
  18. ;        This program is distributed in the hope that it will be
  19. ;        useful, but WITHOUT ANY WARRANTY; without even the implied
  20. ;        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  21. ;        PURPOSE. See the GNU General Public License for more details.
  22. ;
  23. ;        You can find the full GNU GPL online at: http://www.gnu.org/
  24. ;
  25. ;  :Language.    68000/68020 Assembler
  26. ;  :Translator.    Barfly V2.9
  27. ;---------------------------------------------------------------------------*
  28. ;##########################################################################
  29.  
  30.     INCDIR    Includes:
  31.     INCLUDE    lvo/exec.i
  32.     INCLUDE    exec/execbase.i
  33.     INCLUDE    lvo/dos.i
  34.  
  35.     INCLUDE    wdelta.i
  36.     INCLUDE    macros/ntypes.i
  37.  
  38. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  39.  
  40. GL    EQUR    A4        ;a4 ptr to Globals
  41. LOC    EQUR    A5        ;a5 for local vars
  42.  
  43.  ENUM 0
  44.  EITEM WDLT_OK
  45.  EITEM WDLT_NOWDELTA
  46.  EITEM WDLT_HEADCHKSUM
  47.  EITEM WDLT_INCHKSUM
  48.  EITEM WDLT_OUTCHKSUM
  49.  EITEM WDLT_WDLTCHKSUM
  50.  EITEM WDLT_ERROR
  51.  
  52.     STRUCTURE    ReadArgsArray,0
  53.         ULONG    rda_inname
  54.         ULONG    rda_outname
  55.         ULONG    rda_wdname
  56.         LABEL    rda_SIZEOF
  57.  
  58.     NSTRUCTURE    Globals,0
  59.         NAPTR    gl_execbase
  60.         NAPTR    gl_dosbase
  61.         NAPTR    gl_rdargs
  62.         NSTRUCT    gl_rdarray,rda_SIZEOF
  63.         NLONG    gl_insize
  64.         NLONG    gl_inptr
  65.         NLONG    gl_outsize
  66.         NLONG    gl_outptr
  67.         NLONG    gl_wdsize
  68.         NLONG    gl_wdptr
  69.         NALIGNLONG
  70.         NLABEL    gl_SIZEOF
  71.  
  72. ;##########################################################################
  73.  
  74.     PURE
  75.     SECTION    "",CODE
  76.     OUTPUT    C:WPatch
  77.  
  78. VER    MACRO
  79.         dc.b    "WPatch 1.0 "
  80.     DOSCMD    "WDate >t:date"
  81.     INCBIN    "t:date"
  82.         dc.b    " by Bert Jahn <wepl@kagi.com>"
  83.     ENDM
  84.  
  85.         bra    .start
  86.         dc.b    "$VER: "
  87.         VER
  88.         dc.b    " V37+"
  89.     CNOP 0,2
  90. .start
  91.  
  92. ;##########################################################################
  93.  
  94.         link    GL,#gl_SIZEOF        ;GL = globals
  95.         move.l    (4),(gl_execbase,GL)
  96.  
  97.         move.l    #37,d0
  98.         lea    (_dosname),a1
  99.         move.l    (gl_execbase,GL),a6
  100.         jsr    (_LVOOpenLibrary,a6)
  101.         move.l    d0,(gl_dosbase,GL)
  102.         beq    .nodoslib
  103.  
  104.         lea    (_ver),a0
  105.         bsr    _Print
  106.  
  107.         lea    (_template),a0
  108.         move.l    a0,d1
  109.         lea    (gl_rdarray,GL),a0
  110.         move.l    a0,d2
  111.         moveq    #0,d3
  112.         move.l    (gl_dosbase,GL),a6
  113.         jsr    (_LVOReadArgs,a6)
  114.         move.l    d0,(gl_rdargs,GL)
  115.         bne    .argsok
  116.         lea    (_readargs),a0
  117.         bsr    _PrintErrorDOS
  118.         bra    .noargs
  119. .argsok
  120.         bsr    _apply
  121.         move.l    d0,d7
  122.  
  123.         move.l    (gl_rdargs,GL),d1
  124.         move.l    (gl_dosbase,GL),a6
  125.         jsr    (_LVOFreeArgs,a6)
  126. .noargs
  127.         move.l    (gl_dosbase,GL),a1
  128.         move.l    (gl_execbase,GL),a6
  129.         jsr    (_LVOCloseLibrary,a6)
  130. .nodoslib
  131.         unlk    GL
  132.         move.l    d7,d0
  133.         rts
  134.  
  135. ;##########################################################################
  136.  
  137. _apply        moveq    #20,d7            ;rc
  138.  
  139.         move.l    (gl_rdarray+rda_wdname,GL),a0
  140.         bsr    _LoadFile
  141.         move.l    d0,(gl_wdptr,GL)
  142.         beq    .nowd
  143.  
  144.         move.l    d1,d0            ;size
  145.         move.l    (gl_wdptr,GL),a0
  146.         bsr    _wdelta_chk
  147.         move.l    d0,(gl_outsize,GL)
  148.         bpl    .wdok
  149.         neg.l    d0
  150.         move.l    d0,d7            ;rc
  151.         bsr    .error
  152.         bra    .badwd
  153. .wdok
  154.         move.l    #MEMF_ANY,d1
  155.         move.l    (gl_execbase,GL),a6
  156.         jsr    (_LVOAllocVec,a6)
  157.         move.l    d0,(gl_outptr,GL)
  158.         beq    .noout
  159.  
  160.         move.l    (gl_rdarray+rda_inname,GL),a0
  161.         bsr    _LoadFile
  162.         move.l    d0,(gl_inptr,GL)
  163.         beq    .noin
  164.  
  165.         move.l    d1,d0            ;size
  166.         move.l    (gl_inptr,GL),a0
  167.         move.l    (gl_outptr,GL),a1
  168.         move.l    (gl_wdptr,GL),a2
  169.         bsr    _wdelta
  170.         move.l    d0,d7            ;rc
  171.         beq    .ok
  172.         bsr    .error
  173.         bra    .err
  174. .ok
  175.         move.l    (gl_outsize,GL),d0
  176.         move.l    (gl_outptr,GL),a0
  177.         move.l    (gl_rdarray+rda_outname,GL),a1
  178.         bsr    _SaveFile
  179.         tst.l    d0
  180.         bne    .err
  181.         moveq    #20,d7            ;rc
  182. .err
  183.         move.l    (gl_inptr,GL),a1
  184.         move.l    (gl_execbase,GL),a6
  185.         jsr    (_LVOFreeVec,a6)
  186. .noin
  187.         move.l    (gl_outptr,GL),a1
  188.         move.l    (gl_execbase,GL),a6
  189.         jsr    (_LVOFreeVec,a6)
  190. .noout
  191. .badwd
  192.         move.l    (gl_wdptr,GL),a1
  193.         move.l    (gl_execbase,GL),a6
  194.         jsr    (_LVOFreeVec,a6)
  195. .nowd
  196.         move.l    d7,d0            ;rc
  197.         rts
  198.  
  199. .error        lea    (_wdlt_error),a0
  200.         lsl.l    #2,d0
  201.         move.l    (a0,d0.l),a0
  202.         bsr    _Print
  203.         bra    _PrintLn
  204.  
  205. ;----------------------------------------
  206. ; check wdelta data and return output size
  207. ; IN:    d0 = size of wdelta data
  208. ;    a0 = wdelta data
  209. ; OUT:    d0 = output size or negative WDLT_* error
  210.  
  211. _wdelta_chk    movem.l    d1/a0-a1/a5,-(a7)
  212.  
  213.         move.l    a0,a5            ;A5 = wdelta
  214.  
  215.         moveq    #-WDLT_NOWDELTA,d0    ;no wdelta file
  216.         cmp.l    #"WDLT",(a0)+
  217.         bne    .end
  218.         move.l    #wdlt_crchd-4,d0
  219.         bsr    _CRC16
  220.         move.w    d0,d1
  221.         moveq    #-WDLT_HEADCHKSUM,d0    ;header chksum
  222.         cmp.w    (wdlt_crchd,a5),d1
  223.         bne    .end
  224.  
  225.         move.l    (wdlt_lenwd,a5),d0
  226.         lea    (wdlt_wdelta,a5),a0
  227.         bsr    _CRC16
  228.         move.w    d0,d1
  229.         moveq    #-WDLT_WDLTCHKSUM,d0    ;wdelta chksum
  230.         cmp.w    (wdlt_crcwd,a5),d1
  231.         bne    .end
  232.  
  233.         move.l    (wdlt_lenout,a5),d0
  234.  
  235. .end        movem.l    (a7)+,_MOVEMREGS
  236.         rts
  237.  
  238. ;----------------------------------------
  239. ; create output by applying wdelta to input
  240. ; IN:    d0 = input size
  241. ;    a0 = input data
  242. ;    a1 = output data
  243. ;    a2 = wdelta data
  244. ; OUT:    d0 = WDLT_* error
  245.  
  246. _wdelta        movem.l    d1/a0-a5,-(a7)
  247.  
  248.         move.l    a0,a3            ;A3 = input
  249.         move.l    a1,a4            ;A4 = output
  250.         move.l    a2,a5            ;A5 = wdelta
  251.  
  252.         move.l    d0,d1
  253.         moveq    #WDLT_INCHKSUM,d0    ;input chksum
  254.         cmp.l    (wdlt_lenin,a5),d1
  255.         bne    .end
  256.  
  257.         move.l    d1,d0
  258.         move.l    a3,a0
  259.         bsr    _CRC16
  260.         move.w    d0,d1
  261.         moveq    #WDLT_INCHKSUM,d0    ;input chksum
  262.         cmp.w    (wdlt_crcin,a5),d1
  263.         bne    .end
  264.  
  265.         move.l    a3,a0
  266.         move.l    a4,a1
  267.         lea    (wdlt_wdelta,a5),a2
  268.         move.l    (wdlt_lenout,a5),a3
  269.         add.l    a4,a3
  270.  
  271. .loop        cmp.l    a1,a3
  272.         bls    .done
  273.         move.b    (a2)+,d1
  274.         move.b    d1,d0
  275.         and.w    #$1f,d1
  276.         tst.b    d0
  277.         bpl    .4bit
  278. .12bit        lsl.w    #8,d1
  279.         move.b    (a2)+,d1
  280.         add.w    #32,d1
  281. .4bit
  282.     ;d0=cmd d1=length-1
  283.         and.b    #$60,d0
  284.         beq    .equ
  285.         cmp.b    #$40,d0
  286.         blo    .chg
  287.         beq    .add
  288.  
  289. .del        lea    (1,a0,d1.w),a0
  290.         bra    .loop
  291.  
  292. .chg        lea    (1,a0,d1.w),a0
  293. .add        lea    (a1,d1.w),a6
  294.         cmp.l    a6,a3
  295.         bls    .done
  296. .alp        move.b    (a2)+,(a1)+
  297.         dbf    d1,.alp
  298.         bra    .loop
  299.  
  300. .equ        lea    (a1,d1.w),a6
  301.         cmp.l    a6,a3
  302.         bls    .done
  303. .elp        move.b    (a0)+,(a1)+
  304.         dbf    d1,.elp
  305.         bra    .loop
  306.  
  307. .done        moveq    #WDLT_ERROR,d0
  308.         cmp.l    a3,a1
  309.         blo    .end
  310.         beq    .done1
  311.         illegal
  312. .done1        sub.l    (wdlt_lenwd,a5),a2
  313.         sub.l    #wdlt_wdelta,a2
  314.         cmp.l    a5,a2
  315.         bne    .end
  316.  
  317.         move.l    (wdlt_lenout,a5),d0
  318.         move.l    a4,a0
  319.         bsr    _CRC16
  320.         move.w    d0,d1
  321.         moveq    #WDLT_OUTCHKSUM,d0    ;output chksum
  322.         cmp.w    (wdlt_crcout,a5),d1
  323.         bne    .end
  324.  
  325.         moveq    #WDLT_OK,d0
  326.  
  327. .end        movem.l    (a7)+,_MOVEMREGS
  328.         rts
  329.  
  330. ;##########################################################################
  331.  
  332.     INCLUDE    crc16.s
  333.  
  334.     INCDIR    Sources:
  335.     INCLUDE    dosio.i
  336.         Print
  337.         PrintLn
  338.     INCLUDE    error.i
  339.         PrintErrorDOS
  340.     INCLUDE    files.i
  341.         LoadFile
  342.         SaveFile
  343.  
  344. ;##########################################################################
  345.  
  346. _wdlt_error    dc.l    0
  347.         dc.l    _wdlt_1
  348.         dc.l    _wdlt_2
  349.         dc.l    _wdlt_3
  350.         dc.l    _wdlt_4
  351.         dc.l    _wdlt_5
  352.         dc.l    _wdlt_6
  353. _wdlt_1        dc.b    "not a wdelta file",0
  354. _wdlt_2        dc.b    "checksum error in wdelta file header",0
  355. _wdlt_3        dc.b    "wrong input file",0
  356. _wdlt_4        dc.b    "checksum error in output file",0
  357. _wdlt_5        dc.b    "checksum error in wdelta file",0
  358. _wdlt_6        dc.b    "internal error",0
  359.  
  360. _nomem        dc.b    "not enough free memory",10,0
  361. _readargs    dc.b    "read arguments",0
  362. _dosname    dc.b    "dos.library",0
  363. _template    dc.b    "InFile/A"        ;file to apply patch
  364.         dc.b    ",OutFile/A"        ;resulting file
  365.         dc.b    ",WDeltaFile/A"        ;wdelta file
  366.         dc.b    0
  367.  
  368. _ver        VER
  369.         dc.b    10,0
  370.  
  371. ;##########################################################################
  372.  
  373.     END
  374.